﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace FoundationLib.Mail.Configuration
{
	/// <summary>
	/// This class represents configuration settings for SMTP mail connectors.
	/// </summary>
	public class SmtpConfigElement : ConfigurationElement
	{
		/// <summary>
		/// Creates a new <see cref="SmtpConfigElement"/>.
		/// </summary>
		public SmtpConfigElement() : base()
		{
		}

		/// <summary>
		/// Gets the SMTP host.
		/// </summary>
		[ConfigurationProperty("host", IsRequired = true, DefaultValue = "localhost")]
		public string Host
		{
			get
			{
				return (this["host"] as string);
			}
		}

		/// <summary>
		/// Gets the SMTP port to be used.
		/// </summary>
		[ConfigurationProperty("port", DefaultValue = 25)]
		public int Port
		{
			get
			{
				return ((int)this["port"]);
			}
		}

		/// <summary>
		/// Gets a value indicating whether secure socket layer is to be used for connecting to the host.
		/// </summary>
		[ConfigurationProperty("enableSsl", DefaultValue = false)]
		public bool EnableSsl
		{
			get
			{
				return ((bool)this["enableSsl"]);
			}
		}

		/// <summary>
		/// Gets a value indicating whether the default credentials are to be used.
		/// </summary>
		[ConfigurationProperty("useDefaultCredentials", DefaultValue = true)]
		public bool UseDefaultCredentials
		{
			get
			{
				return ((bool)this["useDefaultCredentials"]);
			}
		}

		/// <summary>
		/// Gets the username to be used for connecting to the SMTP host. 
		/// This property is only used if <see cref="UseDefaultCredentials"/> is set to false.
		/// </summary>
		[ConfigurationProperty("username")]
		public string Username
		{
			get
			{
				return (this["username"] as string);
			}
		}

		/// <summary>
		/// Gets the password to be used for connecting to the SMTP host. 
		/// This property is only used if <see cref="UseDefaultCredentials"/> is set to false.
		/// </summary>
		[ConfigurationProperty("password")]
		public string Password
		{
			get
			{
				return (this["password"] as string);
			}
		}

		/// <summary>
		/// Gets the name of the default sender used in the mail header.
		/// </summary>
		[ConfigurationProperty("senderName", IsRequired = true)]
		public string SenderName
		{
			get
			{
				return (this["senderName"] as string);
			}
		}

		/// <summary>
		/// Gets the address of the default sender used in the mail header.
		/// </summary>
		[ConfigurationProperty("senderEmail", IsRequired = true)]
		public string SenderEmail
		{
			get
			{
				return (this["senderEmail"] as string);
			}
		}

		/// <summary>
		/// Gets a value indicating whether emails are to be sent asynchronously rather than synchronously.
		/// </summary>
		[ConfigurationProperty("enableAsyncSend", DefaultValue = false)]
		public bool EnableAsyncSend
		{
			get
			{
				return ((bool)this["enableAsyncSend"]);
			}
		}

		/// <summary>
		/// Gets the timeout for send operations.
		/// </summary>
		[ConfigurationProperty("timeout", DefaultValue = 100)]
		public int Timeout
		{
			get
			{
				return ((int)this["timeout"]);
			}
		}
	}
}
